package com.alpha.crm;

import java.util.ArrayList;

import com.alpha.crm.R;





import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
//import android.database.Cursor;
//import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
//import android.provider.ContactsContract;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
//import android.provider.ContactsContract.Contacts.Data;
@SuppressLint("ParserError")
public class GridViewExampleActivity extends Activity {
    /** Called when the activity is first created. */
	
	private GridviewAdapter mAdapter;
	private ArrayList<String> listCountry;
	private ArrayList<Integer> listFlag;
	//private static final int PICK_CONTACT = 3;
	private GridView gridView;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        prepareList();
        
        // prepared arraylist and passed it to the Adapter class
        mAdapter = new GridviewAdapter(this,listCountry, listFlag);
        
        // Set custom adapter to gridview
        gridView = (GridView) findViewById(R.id.gridView1);
        gridView.setAdapter(mAdapter);
        
        // Implement On Item click listener
        gridView.setOnItemClickListener(new OnItemClickListener() 
        {
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
				Toast.makeText(GridViewExampleActivity.this, mAdapter.getItem(position), Toast.LENGTH_SHORT).show();
				if(position == 0){
				  Intent i = new Intent();
				  i.setClassName("com.android.contacts","com.android.contacts.ContactsListActivity");
				  startActivity(i);
		       			}
				if(position == 1){
				  Intent i = new Intent();
				  i.setClassName("com.android.calendar","com.android.calendar.AgendaActivity");
				  startActivity(i);
				
				}
				if(position == 2){
					Intent myIntent = new Intent(GridViewExampleActivity.this, ContactAdder.class);
		               GridViewExampleActivity.this.startActivity(myIntent);
					
					{}}
				if(position == 3){
					  Intent i = new Intent();
					  i.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
					  startActivity(i);
					
					}
				if(position == 4){
					Intent myIntent = new Intent(GridViewExampleActivity.this, Question.class);
		               GridViewExampleActivity.this.startActivity(myIntent);
					
					}
				if(position == 5){
					//Intent i = new Intent();
					  //i.setClassName("com.android.email","com.android.email.MessageList");
					  //startActivity(i);
					Intent intent = getPackageManager().getLaunchIntentForPackage("com.android.email");
					startActivity(intent);
				}

			}
		});
        
    }
   
   
    
    public void prepareList()
    {
    	  listCountry = new ArrayList<String>();
    	  
    	  listCountry.add("Contacts");
    	  listCountry.add("Calendar");
          listCountry.add("Add Contact");
          listCountry.add("Maps");
          listCountry.add("Questionnaire");
          listCountry.add("Email");
          
          
          listFlag = new ArrayList<Integer>();
          listFlag.add(R.drawable.contactsmain);
          listFlag.add(R.drawable.calendar);
          listFlag.add(R.drawable.addcontact);
          listFlag.add(R.drawable.maps);
          listFlag.add(R.drawable.tasks1);
          listFlag.add(R.drawable.mail);
        
    }
   

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_question, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
	
    if (item.getItemId()==R.id.menu_settings) {
    
       startActivity ( new Intent (GridViewExampleActivity.this, Calendari.class) );
       
            return true;
}
    return super.onOptionsItemSelected(item);
}
}